/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * http://svn.apache.org/repos/asf/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/src/demo/hw/server/
 * http://www.benmccann.com/dev-blog/web-services-tutorial-with-apache-cxf/
 * https://jax-ws.dev.java.net/jax-ws-ea3/docs/annotations.html#2.4%20javax.jws.WebParam|outline
 */
package aic;

import aic.server.Server;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import aic.beans.*;
import aic.misc.DebugPrint;
import aic.ws.OrderManagementService;
import aic.ws.OrderManagementServiceImpl;
import java.math.BigDecimal;
import java.net.URL;
import java.security.Provider.Service;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.jws.soap.SOAPBinding;
import javax.xml.namespace.QName;

public class Main {

    public static void main(String args[]) throws Exception {
        if (true) {
            new Server();
            System.out.println("Server ready...");

            OrderManagementServiceImpl omsi = new OrderManagementServiceImpl();
            omsi.insert_test_data();

//            Thread.sleep(2 * 1000);
//
////            new Client();
//
//            Thread.sleep(5 * 60 * 1000);
//            System.out.println("Server exiting");
//            System.exit(0);
        } else {
            testXML();
        }
    }

    public static void testXML() {

        Customer custom = new Customer();
        custom.setId("customer_id_12");
        custom.setName("custom_name");
        custom.setPayment_preference(Payment_Preference.Bank_Transfer);

        Address adr = new Address();
        adr.setCity("wien");
        adr.setDoor(32);
        adr.setHouse(2);
        adr.setId("id_adress");
        adr.setStreet("Mahü");
        adr.setZip_code("A-1060");

        custom.setAddress(adr);
//        adr.setCustomer(custom);

        Order ord = new Order();
        Order ord2 = new Order();
        ord.setId("foo");
//        ord.setCustomer(custom);
        ord.setOrderDate(new Date());

        ord2.setId("bar");
//        ord2.setCustomer(custom);
        ord2.setOrderDate(new Date());

        List<Order> orderList = Collections.synchronizedList(new LinkedList<Order>());
        orderList.add(ord);
        orderList.add(ord2);

        Item i1 = new Item();
        i1.setProduct_id("iID1");
        i1.setQuantity(10);
        i1.setSingle_unit_price(new BigDecimal(20));
//        i1.setOrderRef(ord);

        Item i2 = new Item();
        i2.setProduct_id("iID2");
        i2.setQuantity(20);
        i2.setSingle_unit_price(new BigDecimal(20));
//        i2.setOrderRef(ord);

        Item i3 = new Item();
        i3.setProduct_id("iID3");
        i3.setQuantity(30);
        i3.setSingle_unit_price(new BigDecimal(30));
//        i3.setOrderRef(ord2);


        List<Item> itemList1 = Collections.synchronizedList(new LinkedList<Item>());
        itemList1.add(i1);
        itemList1.add(i2);
        ord.setItems(itemList1);

        List<Item> itemList2 = Collections.synchronizedList(new LinkedList<Item>());
        itemList2.add(i3);
        ord2.setItems(itemList2);

        custom.setOrders(orderList);

        try {


            JAXBContext context = JAXBContext.newInstance(Customer.class);
            Marshaller m = context.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            m.marshal(custom, System.out);
        } catch (Exception e) {
            System.out.println("Fehler: " + e);
        }
    }
}
